package com.xagcdx.group1.web;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.xagcdx.group1.bean.Staff;
import com.xagcdx.group1.bean.StaffChange;
import com.xagcdx.group1.bean.Summit;
import com.xagcdx.group1.service.StaffChangeService;
import com.xagcdx.group1.service.StaffService;
import com.xagcdx.group1.service.SummitService;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author grou1
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/staffChange")
public class StaffChangeController {
	@Autowired
	private StaffService staffService;
	@Autowired
	private SummitService summitService;
	@Autowired
	private StaffChangeService staffChangeService;
	@RequestMapping("/getinfo")
	public String getinfo(String sid) {
		QueryWrapper<StaffChange> queryWrapper = new QueryWrapper<StaffChange>();
		queryWrapper.eq("sid", sid);
		StaffChange staffChange = staffChangeService.getOne(queryWrapper);
		List<StaffChange> staffChanges = new ArrayList<StaffChange>();
		staffChanges.add(staffChange);
		System.out.println(staffChanges);
		String str = new Gson().toJson(staffChanges);
		System.out.println(str);
		return new Gson().toJson(staffChanges);
	}
	@RequestMapping("/submit")
	public String submit(StaffChange staffChange,String summittype) {
		//根据不同的修改类型进行相应操作
		QueryWrapper<Staff> queryWrapper = new QueryWrapper<Staff>();
		queryWrapper.eq("sid", staffChange.getSid());
		Staff staff = staffService.getOne(queryWrapper);
		QueryWrapper<StaffChange> queryWrapper2 = new QueryWrapper<StaffChange>();
		queryWrapper2.eq("sid", staffChange.getSid());
		StaffChange staffChange2 = staffChangeService.getOne(queryWrapper2);
		QueryWrapper<Summit> queryWrapper3 = new QueryWrapper<Summit>();
		queryWrapper3.eq("sid", staffChange.getSid());
		Summit summit = summitService.getOne(queryWrapper3);
		//0:转正
		if("0".equals(summittype)) {
			staffChange2.setStaffstatu("0");
			boolean save = staffChangeService.update(staffChange2, queryWrapper2);
			if(save) {
				summit.setSummitstatu("1");
				summit.setSummittype(summittype);
				boolean save2 = summitService.update(summit, queryWrapper3);
				if(save2) {
					return "1";
				}
			}else {
				return "0";
			}
		}else if("1".equals(summittype)) {
			//调薪
			staffChange2.setSalarytype(staffChange.getSalarytype());
			boolean save = staffChangeService.update(staffChange2, queryWrapper2);
			if(save) {
				summit.setSummitstatu("1");
				summit.setSummittype(summittype);
				boolean save2 = summitService.update(summit, queryWrapper3);
				if(save2) {
					return "1";
				}
			}else {
				return "0";
			}
		}else if("2".equals(summittype)) {
			//调岗
			staffChange2.setDid(staffChange.getDid());
			staffChange2.setJid(staffChange.getJid());
			staffChange2.setJtid(staffChange.getJtid());
			boolean save = staffChangeService.update(staffChange2, queryWrapper2);
			if(save) {
				summit.setSummitstatu("1");
				summit.setSummittype(summittype);
				boolean save2 = summitService.update(summit, queryWrapper3);
				if(save2) {
					return "1";
				}
			}else {
				return "0";
			}
		}else if("3".equals(summittype)) {
			//离职
			staffChange2.setStaffstatu("3");
			boolean save = staffChangeService.update(staffChange2, queryWrapper2);
			if(save) {
				summit.setSummitstatu("1");
				summit.setSummittype(summittype);
				boolean save2 = summitService.update(summit, queryWrapper3);
				if(save2) {
					return "1";
				}
			}else {
				return "0";
			}
		}else if("6".equals(summittype)) {
			//信息修改
			staffChange2.setName(staffChange.getName());
			staffChange2.setSex(staffChange.getSex());
			staffChange2.setPlace(staffChange.getPlace());
			staffChange2.setPolitictype(staffChange.getPolitictype());
			staffChange2.setEmail(staffChange.getEmail());
			staffChange2.setSnum(staffChange.getSnum());
			staffChange2.setBplace(staffChange.getBplace());
			staffChange2.setTelenum(staffChange.getTelenum());
			staffChange2.setGradschool(staffChange.getGradschool());
			staffChange2.setMajor(staffChange.getMajor());
			staffChange2.setDegree(staffChange.getDegree());
			staffChange2.setBcardnum(staffChange.getBcardnum());
			staffChange2.setBank(staffChange.getBank());
			staffChange2.setScardnum(staffChange.getScardnum());
			staffChange2.setSelfexperience(staffChange.getSelfexperience());
			staffChange2.setFamilyinfo(staffChange.getFamilyinfo());
			staffChange2.setStaffdesc(staffChange.getStaffdesc());
			boolean save = staffChangeService.update(staffChange2, queryWrapper2);
			if(save) {
				summit.setSummitstatu("1");
				summit.setSummittype(summittype);
				boolean save2 = summitService.update(summit, queryWrapper3);
				if(save2) {
					return "1";
				}
			}else {
				return "0";
			}
		}
		return "0";
		
	}
}

